home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / zilog / zilog_1.c next >
C/C++ Source or Header  |  1996-04-07  |  5KB  |  224 lines

  1. /*
  2.  *
  3.  *
  4.  *        Programme d‚monstration 1 - Simple terminal entre deux machines
  5.  *
  6.  *        Ce programme transfŠre … 19200 Bits/Sec. en 8 Bits Parit‚ Paire
  7.  *        1 bit de Stop.
  8.  *        Il opŠre en mode simple, ‚mission d'un caratŠre et test si caractŠre
  9.  *        re‡u avant ‚ventuellement sa prise en compte.
  10.  *
  11.  *
  12.  *        FunShip (c) 28 Avril 1995 - ATARI Falcon030
  13.  *
  14.  */
  15.  
  16.  
  17. #include <stdio.h>
  18. #include <tos.h>
  19.  
  20. #define    TRUE        1
  21. #define    FALSE        0
  22.  
  23. #define    SCC_CONTROLA    0xFFFF8C81L        /* Registers Z85C30's addresses*/
  24. #define    SCC_DATAA    0xFFFF8C83L
  25. #define    SCC_CONTROLB    0xFFFF8C85L
  26. #define    SCC_DATAB    0xFFFF8C87L
  27.  
  28. #define    WR1        1
  29. #define    WR2        2
  30. #define    WR3        3
  31. #define    WR4        4
  32. #define    WR5        5
  33. #define    WR6        6
  34. #define    WR7        7
  35. #define    WR8        8
  36. #define    WR9        9
  37. #define    WR10        10
  38. #define    WR11        11
  39. #define    WR12        12
  40. #define    WR13        13
  41. #define    WR14        14
  42. #define    WR15        15
  43.  
  44. #define    RR1        1
  45. #define    RR2        2
  46. #define    RR3        3
  47. #define    RR10        10
  48. #define    RR12        12
  49. #define    RR13        13
  50. #define    RR15        15
  51.  
  52. /*
  53.  *        Primitives d'accŠs aux registres du ZILOG
  54.  */
  55.  
  56. void SCCPut(int Canal,int Value,int Register)
  57. /*
  58.     This procedure put a value in any register of Z85C30
  59.     
  60.     Inputs:    Value is the byte value to store
  61.         Register is the number of target register
  62.     Outputs:None
  63. */
  64. {
  65.   if(Canal == 'B')
  66.   {
  67.     *(char *)SCC_CONTROLB    = Register;
  68.     *(char *)SCC_CONTROLB    = Value;
  69.   }
  70.   else
  71.   {
  72.     *(char *)SCC_CONTROLA    = Register;
  73.     *(char *)SCC_CONTROLA    = Value;
  74.   }
  75. }
  76.  
  77. int SCCGet(int Channel, int Register)
  78. /*
  79.     This function read a value from any register of Z85C30
  80.     
  81.     Inputs:    Register is the number of source register
  82.     Outputs:Return the register's value
  83. */
  84. {
  85.   int    Value;
  86.   
  87.   if(Channel == 'B')
  88.   {
  89.     *(char *)SCC_CONTROLB    = Register;
  90.     Value            = *(char *)SCC_CONTROLB;
  91.   }
  92.   else
  93.   {
  94.     *(char *)SCC_CONTROLA    = Register;
  95.     Value            = *(char *)SCC_CONTROLA;
  96.   }
  97.   return(Value);
  98. }
  99.  
  100. /*
  101.  *    Primitives plus haut niveaux: Initialisation, Emission, Test et R‚ception
  102.  */
  103.  
  104. void SCCInit(int Channel)
  105. /*
  106.     Initialize the chip in 19200 Bits/Sec, Parity Even, 1 Stop bit and 8 Bits Data
  107.     No interrupts required.
  108. */
  109. {
  110.   SCCPut(Channel,0x00,WR3);            /* Receiver Off */
  111.   SCCPut(Channel,0x00,WR5);            /* Transceiver Off */
  112.   SCCPut(Channel,0x00,WR1);            /* no ITs selected */
  113.   SCCPut(Channel,0x82,WR2);            /* Interrupt Vector, but not used */
  114.   SCCPut(Channel,0x47,WR4);            /* Async. 1 Stop parity Even and Clk/16 */
  115.   SCCPut(Channel,0x00,WR9);            /* Disbale all interrupts */
  116.   SCCPut(Channel,0x00,WR10);            /* NRZ Code mode -> RS232C */
  117.   SCCPut(Channel,0x50,WR11);            /* RxClk = TxClk = BR */
  118.   SCCPut(Channel,0x00,WR15);            /* No special interrupts */
  119.   SCCPut(Channel,0xA3,WR14);            /* BR -> PCLK */
  120.   SCCPut(Channel,0x0B,WR12);            /* Divide value LSB */
  121.   SCCPut(Channel,0x00,WR13);            /* Divide value MSB => 19200 Bauds */
  122.   
  123.   SCCPut(Channel,0xC1,WR3);            /* 8 Bits and enable receiver */
  124.   SCCPut(Channel,0xE8,WR5);            /* 8 Bits and ebale transceiver */
  125. }
  126.  
  127. void SCCOut(int Channel, int Byte)
  128. /*
  129.     Send a character trough the output data register.
  130. */
  131. {
  132.   if(Channel == 'B')
  133.     *(char *)SCC_DATAB = Byte;
  134.   else
  135.     *(char *)SCC_DATAA = Byte;
  136. }
  137.  
  138. int SCCReceived(int Channel)
  139. /*
  140.     Return True if a character is received else false. A character is arrived if
  141.     the bit 0 of RR0 is set.
  142. */
  143. {
  144.   int    Etat;
  145.   
  146.   if(Channel == 'B')
  147.     Etat = *(char *)SCC_CONTROLB & 0x01;
  148.   else
  149.     Etat = *(char *)SCC_CONTROLA & 0x01; 
  150.   return(Etat); 
  151. }
  152.  
  153. int SCCIn(int Channel)
  154. /*
  155.     Get a character from the input data register.
  156. */
  157. {
  158.   if(Channel == 'B')
  159.     return(*(char *)SCC_DATAB);
  160.   else
  161.     return(*(char *)SCC_DATAA);
  162. }
  163.  
  164. /*
  165.  *    Programme principal de test
  166.  */
  167.  
  168. int main(void)
  169. {
  170.   unsigned int    Character;
  171.   int        *OldPile;
  172.   int        Colonne;
  173.   
  174.   printf("\033E");
  175.   printf("\t\tZILOG Z85C30: Transmition/Reception by Registers's Read/Write\n");
  176.   printf("\t\tPress ESC to exit\n");
  177.   printf("\t\t=============================================================\n\n");
  178.  
  179.   printf("Z85C30 programmed at 19200 bits/s, Parity even, 1 Stop bit and 8 bits data\n");
  180.   printf("On its B Channel\n\n");
  181.   
  182.   OldPile    = (int *)Super(0L);        /* Go to supervisor mode */
  183.   
  184.   SCCInit('B');                    /* Initialize the Zilog */
  185.   Colonne = 1;
  186.   Character = (unsigned char)Crawio(0xFF);    /* Reading a character */
  187.   while(Character != 27)
  188.   {
  189.     if(Character != 0)                /* a key is pressed */
  190.     {
  191.       if(Colonne < 80)
  192.       {
  193.         printf("%c",Character);
  194.         Colonne++;
  195.       }
  196.       else                    /* Go back top line */
  197.       {
  198.         Colonne = 1;
  199.         printf("\n");
  200.         printf("%c",Character);
  201.       }
  202.       SCCOut('B',Character);            /* Sending its ASCII code */
  203.     }
  204.     if(SCCReceived('B'))            /* If a character is arrived */
  205.     {
  206.       if(Colonne < 80)
  207.       {
  208.         printf("%c",SCCIn('B'));        /* Display it */
  209.         Colonne++;
  210.       }
  211.       else                    /* Go back top line */
  212.       {
  213.         Colonne = 1;
  214.         printf("\n");
  215.         printf("%c",SCCIn('B'));        /* Display it */
  216.       }
  217.     }
  218.     Character = (unsigned char)Crawio(0xFF);    /* Test another key */
  219.   }
  220.   Super(OldPile);                /* Go back user mode */
  221.   return(0);                    /* Return code for the Shell */
  222. }
  223.  
  224.